#include "../include/SplitToolCppjieba.h"
#include "../include/simhash/cppjieba/Jieba.hpp"

#include <sstream>

using std::istringstream;

SplitToolCppjieba::SplitToolCppjieba(){ }

SplitToolCppjieba::~SplitToolCppjieba(){ }

vector<string> SplitToolCppjieba::cut(const string& sentence){

    vector<string> splitResult;

    const char* const DICT_PATH = "../include/simhash/cppjieba/dict/jieba.dict.utf8";
    const char* const HMM_PATH = "../include/simhash/cppjieba/dict/hmm_model.utf8";
    const char* const USER_DICT_PATH = "../include/simhash/cppjieba/dict/user.dict.utf8";
    const char* const IDF_PATH = "../include/simhash/cppjieba/dict/idf.utf8";
    const char* const STOP_WORD_PATH = "../include/simhash/cppjieba/dict/stop_words.utf8";

    //创建jieba对象
    cppjieba::Jieba jieba(  DICT_PATH,
                            HMM_PATH,
                            IDF_PATH);
    vector<string> words;

    jieba.CutForSearch(sentence, words);
    
    //分割，以空格划分
    string splitWords = limonp::Join(words.begin(), words.end(), " ");

    string splitWord;//单个分割词
    istringstream doc(splitWords);//处理string
    while(doc >> splitWord){
        //将每个词存入vector
        splitResult.push_back(splitWord);
    }

    return splitResult;
}